package com.xtremeprog;

import junit.framework.TestCase;
import org.apache.commons.io.IOUtils;

import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: denny
 * Date: Feb 25, 2009
 * Time: 4:47:49 PM
 * To change this template use File | Settings | File Templates.
 */
public class SquirrelTestCase extends TestCase {

    public void testExtract() throws Exception {
        InputStream regis = SquirrelTestCase.class.getClassLoader().getResourceAsStream("reg");
        InputStream htmlfileis = SquirrelTestCase.class.getClassLoader().getResourceAsStream("htmlfile");
        String pattern = IOUtils.toString(regis, "utf-8");
        String content = IOUtils.toString(htmlfileis, "utf-8");
        long start = System.currentTimeMillis();
        List<Map<String, String>> extract = Squirrel.extract(pattern, content);
        assertEquals(10, extract.size());
    }

    public void testExtract1() throws Exception {
        InputStream regis = SquirrelTestCase.class.getClassLoader().getResourceAsStream("reg1");
        InputStream htmlfileis = SquirrelTestCase.class.getClassLoader().getResourceAsStream("htmlfile");
        String pattern = IOUtils.toString(regis, "utf-8");
        String content = IOUtils.toString(htmlfileis, "utf-8");
        long start = System.currentTimeMillis();
        List<Map<String, String>> extract = Squirrel.extractWith(pattern, content, "&&&*&&&", "***", "***");
        assertEquals(10, extract.size());
    }
}
